//
//  ConverterController.m
//  DDSQuickLook
//
//  Created by Torsten Kammer on 18.02.08.
//  Copyright 2008 Ferroequinologist.de. All rights reserved.
//

#import "ConverterController.h"


@implementation ConverterController

- (void)dealloc
{
    CFRelease((CFArrayRef) fileFormats);
    [super dealloc];
}

- (void)awakeFromNib
{
    fileFormats = (NSArray *) CGImageDestinationCopyTypeIdentifiers();
    NSMutableArray *fileDisplayNames = [[NSMutableArray alloc] init];
    for (NSString *string in fileFormats)
    {
        CFStringRef displayName = UTTypeCopyDescription((CFStringRef) string);
        if (!displayName) displayName = CFStringCreateCopy(kCFAllocatorDefault, (CFStringRef) string);
        [fileDisplayNames addObject:(NSObject *) displayName];
        CFRelease(displayName);
    }
    
    [imageFormatChooser addItemsWithTitles:fileDisplayNames];
    [prefImageFormatChooser addItemsWithTitles:fileDisplayNames];
    
    // For fun: Create a save panel.
    NSSavePanel *panel = [NSSavePanel savePanel];
    [panel setAccessoryView:accessoryView];
    [panel runModal];
    
    CFArrayRef inputFormat = CGImageSourceCopyTypeIdentifiers();
    NSLog(@"valid export formats: %@\n\nvalid import formats: %@", fileFormats, inputFormat);
    CFRelease(inputFormat);
}

- (IBAction)ddsPrefChange:(id)sender;
{
    NSUInteger index = [prefDDDSFormatChooser indexOfSelectedItem];
    if (index == 0)
    {
        // Set to ask
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"ddsAutomatic"];
    }
    else if (index == 2)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt1" forKey:@"ddsFormat"];
        [ddsFormatChooser selectItemAtIndex:0];
    }
    else if (index == 3)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt3" forKey:@"ddsFormat"];
        [ddsFormatChooser selectItemAtIndex:0];
    }
    else if (index == 4)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt5" forKey:@"ddsFormat"];
        [ddsFormatChooser selectItemAtIndex:0];
    }
}
- (IBAction)imagePrefChange:(id)sender;
{
}
- (IBAction)ddsChange:(id)sender;
{
    NSUInteger index = [prefDDDSFormatChooser indexOfSelectedItem];
    if (index == 0)
    {
        // Set to ask
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"ddsAutomatic"];
    }
    else if (index == 2)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt1" forKey:@"ddsFormat"];
        [prefDDDSFormatChooser selectItemAtIndex:0];
    }
    else if (index == 3)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt3" forKey:@"ddsFormat"];
        [prefDDDSFormatChooser selectItemAtIndex:0];
    }
    else if (index == 4)
    {
        [[NSUserDefaults standardUserDefaults] setObject:@"dxt5" forKey:@"ddsFormat"];
        [prefDDDSFormatChooser selectItemAtIndex:0];
    }
}
- (IBAction)imageChange:(id)sender;
{
}

@end
